{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Unique Email Addresses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numUniqueEmails"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #独特的电子邮件地址"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>每个 <strong>有效电子邮件地址</strong> 都由一个 <strong>本地名</strong> 和一个 <strong>域名</strong> 组成，以 <code>'@'</code> 符号分隔。除小写字母之外，电子邮件地址还可以含有一个或多个&nbsp;<code>'.'</code> 或 <code>'+'</code> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，在&nbsp;<code>alice@leetcode.com</code>中，&nbsp;<code>alice</code>&nbsp;是 <strong>本地名</strong> ，而&nbsp;<code>leetcode.com</code>&nbsp;是 <strong>域名</strong> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果在电子邮件地址的<strong> 本地名 </strong>部分中的某些字符之间添加句点（<code>'.'</code>），则发往那里的邮件将会转发到本地名中没有点的同一地址。请注意，此规则 <strong>不适用于域名</strong> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>\"alice.z@leetcode.com”</code> 和 <code>“alicez@leetcode.com”</code>&nbsp;会转发到同一电子邮件地址。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果在<strong> 本地名 </strong>中添加加号（<code>'+'</code>），则会忽略第一个加号后面的所有内容。这允许过滤某些电子邮件。同样，此规则 <strong>不适用于域名</strong> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如 <code>m.y+name@email.com</code> 将转发到 <code>my@email.com</code>。</li>\n",
    "</ul>\n",
    "\n",
    "<p>可以同时使用这两个规则。</p>\n",
    "\n",
    "<p>给你一个字符串数组 <code>emails</code>，我们会向每个 <code>emails[i]</code> 发送一封电子邮件。返回实际收到邮件的不同地址数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>emails = [\"test.email+alex@leetcode.com\",\"test.e.mail+bob.cathy@leetcode.com\",\"testemail+david@lee.tcode.com\"]\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>实际收到邮件的是 \"testemail@leetcode.com\" 和 \"testemail@lee.tcode.com\"。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>emails = [\"a@leetcode.com\",\"b@leetcode.com\",\"c@leetcode.com\"]\n",
    "<strong>输出：</strong>3\n",
    "</pre>\n",
    "\n",
    "<p><br />\n",
    "<strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= emails.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= emails[i].length&nbsp;&lt;= 100</code></li>\n",
    "\t<li><code>emails[i]</code> 由小写英文字母、<code>'+'</code>、<code>'.'</code> 和 <code>'@'</code> 组成</li>\n",
    "\t<li>每个 <code>emails[i]</code> 都包含有且仅有一个 <code>'@'</code> 字符</li>\n",
    "\t<li>所有本地名和域名都不为空</li>\n",
    "\t<li>本地名不会以 <code>'+'</code> 字符作为开头</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [unique-email-addresses](https://leetcode.cn/problems/unique-email-addresses/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [unique-email-addresses](https://leetcode.cn/problems/unique-email-addresses/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"test.email+alex@leetcode.com\",\"test.e.mail+bob.cathy@leetcode.com\",\"testemail+david@lee.tcode.com\"]', '[\"a@leetcode.com\",\"b@leetcode.com\",\"c@leetcode.com\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=[]\n",
    "        for i in emails:\n",
    "            t=''\n",
    "            s=''\n",
    "            flag=True\n",
    "            for j in range(len(i)):\n",
    "                if i[j]=='.' :\n",
    "                    continue\n",
    "                elif i[j]=='@':\n",
    "                    s=i[j::]\n",
    "                    break\n",
    "                elif i[j]=='+':\n",
    "                    flag=False\n",
    "                elif flag:\n",
    "                    t+=i[j]\n",
    "            if not t+s in ans:\n",
    "                ans.append(t+s)\n",
    "        return len(ans)\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        hash_map = {}\n",
    "        for email in emails:\n",
    "            email, domain = email.split(\"@\")\n",
    "            email = email.split(\"+\")[0]\n",
    "            email = email.replace(\".\", \"\")\n",
    "            hash_map[email + \"@\" + domain] = 1\n",
    "        return len(hash_map)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        n = len(emails)\n",
    "        ans = set()\n",
    "        for i, x in enumerate(emails):\n",
    "            emails[i] = x.split(\"@\")\n",
    "            emails[i][0] = emails[i][0].replace(\".\", \"\")\n",
    "            emails[i][0] = emails[i][0].split(\"+\")[0]\n",
    "            emails[i] = emails[i][0] + \"@\" + emails[i][1]\n",
    "            ans.add(emails[i])\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+', 1)[0]  # 去掉本地名第一个加号之后的部分\n",
    "            local = local.replace('.', '')  # 去掉本地名中所有的句点\n",
    "            emailSet.add(local + email[i:])\n",
    "        return len(emailSet)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in range(len(emails)):\n",
    "            a1,a2=emails[i].split(\"@\")\n",
    "            # print(a1)\n",
    "            # print(a2)\n",
    "            a1=a1.replace(\".\",\"\")\n",
    "            a11=a1.split(\"+\")[0]\n",
    "            # print(j)\n",
    "            # print(a1)\n",
    "            # for i in range(len(a1)):\n",
    "            #     if a1[i]=='+':\n",
    "            #         a1=a1[:i]\n",
    "            #         break\n",
    "            ans.add(a11+\"@\"+a2)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+',1)[0]\n",
    "            local = local.replace('.','')\n",
    "            emailSet.add(local+email[i:])\n",
    "        return len(emailSet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans = set()\n",
    "        for e in emails:\n",
    "            x,y = e.split('@')\n",
    "            x = x.replace('.','')\n",
    "            p = x.find('+')\n",
    "            if p!=-1:\n",
    "                x = x[:p]\n",
    "            ans.add((x,y))\n",
    "        #print(ans)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in range(len(emails)):\n",
    "            a1,a2=emails[i].split(\"@\")\n",
    "            # print(a1)\n",
    "            # print(a2)\n",
    "            a1=a1.replace(\".\",\"\")\n",
    "            a11=a1.split(\"+\")[0]\n",
    "            # print(j)\n",
    "            # print(a1)\n",
    "            # for i in range(len(a1)):\n",
    "            #     if a1[i]=='+':\n",
    "            #         a1=a1[:i]\n",
    "            #         break\n",
    "            ans.add(a11+\"@\"+a2)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in range(len(emails)):\n",
    "            a1,a2=emails[i].split(\"@\")\n",
    "            # print(a1)\n",
    "            # print(a2)\n",
    "            a1=a1.replace(\".\",\"\")\n",
    "            for i in range(len(a1)):\n",
    "                if a1[i]=='+':\n",
    "                    a1=a1[:i]\n",
    "                    break\n",
    "            ans.add(a1+\"@\"+a2)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans = set()\n",
    "        for email in emails:\n",
    "            address = email.split(\"@\")\n",
    "            name = address[0].split(\"+\")[0].replace(\".\", \"\") + \"@\" + address[1]\n",
    "            ans.add(name)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        unique = set()\n",
    "        for e in emails:\n",
    "            local, domain = e.split(\"@\")\n",
    "            local = local.split(\"+\")[0]\n",
    "\n",
    "            local = local.replace(\".\", \"\")\n",
    "\n",
    "            unique.add((local, domain))\n",
    "        return len(unique)\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@') \n",
    "            local = email[:i].split('+', 1)[0]  # 去掉本地名第一个加号之后的部分\n",
    "            local = local.replace('.', '')  # 去掉本地名中所有的句点\n",
    "            emailSet.add(local + email[i:])\n",
    "        return len(emailSet)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans = set()\n",
    "        for email in emails:\n",
    "            email_list = email.split('@')\n",
    "            local, space = email_list[0], email_list[1]\n",
    "            temp = local.split('+')\n",
    "            realLocal = ''.join(temp[0].split('.'))\n",
    "            realEmail = ''.join([realLocal,'@',space])\n",
    "            if realEmail not in ans:\n",
    "                ans.add(realEmail)\n",
    "        return len(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        sets=set()\n",
    "        for email in emails:\n",
    "            idx1=email.find(\"+\")\n",
    "            idx2=email.find(\"@\")\n",
    "            if idx1!=-1 and idx1<idx2: #本地名里有+\n",
    "                loc=email[0:idx1].replace(\".\",\"\")\n",
    "            else:\n",
    "                loc=email[0:idx2].replace(\".\",\"\")\n",
    "            domain=email[idx2:len(email)]\n",
    "            sets.add(loc+domain)\n",
    "        # print(sets)\n",
    "        \n",
    "        return len(sets)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+',1)[0]\n",
    "            local = local.replace('.','')\n",
    "            emailSet.add(local+email[i:])\n",
    "        return len(emailSet)\n",
    "        \n",
    "        # n = len(emails)\n",
    "        # res = set()\n",
    "        # for i in range(n):\n",
    "        #     # 对每个邮件地址做处理\n",
    "        #     email = emails[i]\n",
    "            \n",
    "        #     username = email.split(\"@\")[0]\n",
    "        #     address = email.split(\"@\")[1]\n",
    "        #     realname = username.split(\"+\")[0]\n",
    "        #     finalname = \"\".join(realname.split(\".\"))\n",
    "        #     print(finalname+address)\n",
    "        #     res.add(finalname+\"@\"+address)\n",
    "        # return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def process(email):\n",
    "    local, domain = email.split('@')\n",
    "    i = local.find('+')\n",
    "    if i >= 0:\n",
    "        local = local[:i]\n",
    "    return local.translate(str.maketrans({'.': None})) + '@' + domain\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len(set({process(email) for email in emails}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in range(len(emails)):\n",
    "            a1,a2=emails[i].split(\"@\")\n",
    "            # print(a1)\n",
    "            # print(a2)\n",
    "            a1=a1.replace(\".\",\"\")\n",
    "            j=a1.find(\"+\")\n",
    "            if j>=0:\n",
    "                a1=a1[:j]\n",
    "            # print(j)\n",
    "            # print(a1)\n",
    "            # for i in range(len(a1)):\n",
    "            #     if a1[i]=='+':\n",
    "            #         a1=a1[:i]\n",
    "            #         break\n",
    "            ans.add(a1+\"@\"+a2)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        # seen = set()\n",
    "        # for e in emails:\n",
    "        #     pre, domain = e.split('@')\n",
    "        #     idx = pre.find('+')\n",
    "        #     if idx >= 0:\n",
    "        #         pre = pre[:idx]\n",
    "        #     pre = pre.replace('.', '')\n",
    "        #     seen.add(pre+'@'+domain)\n",
    "        # return len(seen)\n",
    "\n",
    "        # -----------------------------------\n",
    "        seen = set()\n",
    "        for e in emails:\n",
    "            pre, domain = e.split('@')\n",
    "            pre = pre.split('+')[0]\n",
    "            pre = pre.replace('.', '')\n",
    "            seen.add(pre+'@'+domain)\n",
    "        return len(seen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        s = set()\n",
    "        for email in emails:\n",
    "            m, n = email.split(\"@\")\n",
    "            m = m.split(\"+\")[0].replace('.', '')\n",
    "            s.add(m + \"@\" + n)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        email_real=[]\n",
    "        for email in emails:\n",
    "            email_local=email.split('@')[0]\n",
    "            email_path=email.split('@')[-1]\n",
    "            new_local=''\n",
    "            for s in email_local:\n",
    "\n",
    "                if s =='.':\n",
    "                    continue\n",
    "                elif s=='+':\n",
    "                    break\n",
    "                else:\n",
    "                    new_local+=s\n",
    "            # new_path=''\n",
    "\n",
    "            # for p in email_path:\n",
    "                \n",
    "            #     if p=='+':\n",
    "            #         break\n",
    "            #     else:\n",
    "            #         new_path+=p\n",
    "            email_=new_local+'@'+email_path\n",
    "            if email_ not in email_real:\n",
    "                email_real.append(email_)\n",
    "        print(email_real)\n",
    "        return len(email_real) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: list[str]) -> int:\n",
    "        se = set()\n",
    "        for email in emails:\n",
    "          p = email.split('@')\n",
    "          p[0].replace('.', '')\n",
    "          s1 = p[0].split('+')\n",
    "          s2 = s1[0].split('.')\n",
    "          res = \"\"\n",
    "          for c in s2:\n",
    "              res += c\n",
    "          res += '@'\n",
    "          res += p[1]\n",
    "          se.add(res)\n",
    "        print(len(se))\n",
    "        return len(se)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        email_address = set()\n",
    "        for email in emails:\n",
    "            local_name = email.split('@')[0]\n",
    "            domain_name = email.split('@')[1]\n",
    "            local_name = local_name.replace('.', '')\n",
    "            local_name = local_name.split('+')[0]\n",
    "            unique_email = local_name + '@' + domain_name\n",
    "            email_address.add(unique_email)\n",
    "        return len(email_address)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        rs=set()   \n",
    "        for i in emails:\n",
    "            leni=len(i)\n",
    "            z=0\n",
    "            yu=''\n",
    "            fi=i[::-1]\n",
    "            for k in range(leni):\n",
    "                if fi[k]=='@':\n",
    "                    yu=fi[:k+1][::-1]\n",
    "                    bendi=fi[k+1:][::-1]\n",
    "                    break\n",
    "            while z<leni-k-1:\n",
    "                if bendi[z]=='+':\n",
    "                    bendi=bendi[:z]\n",
    "                    break\n",
    "                elif bendi[z]=='.':\n",
    "                    bendi=bendi[:z]+bendi[z+1:]\n",
    "                    leni-=1\n",
    "                else:\n",
    "                    z+=1\n",
    "            rs.add(bendi+yu)\n",
    "        return len(rs)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        list1 = []\n",
    "        for i in emails:\n",
    "            namelist = i.split('@')\n",
    "            namelist[0] = namelist[0].replace('.',\"\")\n",
    "            namelist[0] = namelist[0].split(\"+\")[0]\n",
    "            list1.append(namelist[0]+'@'+namelist[1])\n",
    "        return len(set(list1))    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in range(len(emails)):\n",
    "            a1,a2=emails[i].split(\"@\")\n",
    "            # print(a1)\n",
    "            # print(a2)\n",
    "            a1=a1.replace(\".\",\"\")\n",
    "            j=a1.find(\"+\")\n",
    "            if j>=0:\n",
    "                a1=a1[:j]\n",
    "            # print(j)\n",
    "            # print(a1)\n",
    "            # for i in range(len(a1)):\n",
    "            #     if a1[i]=='+':\n",
    "            #         a1=a1[:i]\n",
    "            #         break\n",
    "            ans.add(a1+\"@\"+a2)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        h = []\n",
    "        for adress in emails:\n",
    "            actual_adress = ''\n",
    "            i = 0\n",
    "            while i < len(adress):\n",
    "                if adress[i] == '+':\n",
    "                    while adress[i] != '@':\n",
    "                        i += 1\n",
    "                    break\n",
    "                elif adress[i] == '@':\n",
    "                    break\n",
    "                elif adress[i] != '.':\n",
    "                    actual_adress += adress[i]\n",
    "                i += 1\n",
    "            actual_adress += adress[i:]\n",
    "            if actual_adress not in h:\n",
    "                h.append(actual_adress)\n",
    "        return len(h)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        \n",
    "        ans =set()\n",
    "        for email in emails:\n",
    "            local_name,domain_name=email.split('@',1)\n",
    "            temp=''\n",
    "            for ch in local_name:\n",
    "                if ch =='.':\n",
    "                    continue\n",
    "                elif ch=='+':\n",
    "                    break\n",
    "                else:\n",
    "                    temp+=ch\n",
    "            temp+='@'\n",
    "            temp+=domain_name\n",
    "            ans.add(temp)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len(set(sp[0].split(\"+\")[0].replace(\".\", \"\") + \"@\" + sp[1] if (sp := email.split(\"@\")) else \"\" for email in emails))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+', 1)[0]  # 去掉本地名第一个加号之后的部分\n",
    "            local = local.replace('.', '')  # 去掉本地名中所有的句点\n",
    "            emailSet.add(local + email[i:])\n",
    "        return len(emailSet)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res = set()\n",
    "        for email in emails:\n",
    "            parts, tmp = email.split('@'), []\n",
    "            for l in parts[0]:\n",
    "                if l == '+': break\n",
    "                elif l == '.': continue\n",
    "                else: tmp.append(l)\n",
    "            res.add(''.join(tmp) + '@' + parts[1])\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for i in emails:\n",
    "            email=i.split(\"@\")\n",
    "            email[0]=email[0].replace(\".\",\"\")\n",
    "            email[0]=email[0].split(\"+\")[0]\n",
    "            ans.add(\"@\".join(email))\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        unique_emails = set()\n",
    "        for email in emails:\n",
    "            parts = email.split('@')\n",
    "            local = parts[0]\n",
    "            if '+' in local:\n",
    "                tmp = local.split('+')\n",
    "                local = tmp[0]\n",
    "            local = local.replace('.', '')\n",
    "            unique_emails.add(local + '@' + parts[1])\n",
    "        \n",
    "        return len(unique_emails)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        seen = set()\n",
    "        for e in emails:\n",
    "            pre, domain = e.split('@')\n",
    "            idx = pre.find('+')\n",
    "            if idx >= 0:\n",
    "                pre = pre[:idx]\n",
    "            pre = pre.replace('.', '')\n",
    "            seen.add(pre+'@'+domain)\n",
    "        return len(seen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\r\n",
    "        emailSet = set()\r\n",
    "        for email in emails:\r\n",
    "            i = email.index('@')\r\n",
    "            local = email[:i].split('+', 1)[0]  # 去掉本地名第一个加号之后的部分\r\n",
    "            local = local.replace('.', '')  # 去掉本地名中所有的句点\r\n",
    "            emailSet.add(local + email[i:])\r\n",
    "        return len(emailSet)\r\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res = []\n",
    "        for emile in emails:\n",
    "            name,domain = emile.split('@')\n",
    "            name_new = name.split('+')[0].replace('.','')\n",
    "            name_new = name_new + \"@\"+domain\n",
    "            if name_new not in res:\n",
    "                res.append(name_new)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        s = set()\n",
    "        for email in emails:\n",
    "            l,r = email.split(\"@\")\n",
    "            l = l.split(\"+\")[0]\n",
    "            l = l.replace('.','')\n",
    "            cur = l +\"@\"+ r\n",
    "            s.add(cur)\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        a=[]\n",
    "        for i in emails:\n",
    "            b=''\n",
    "            j=0\n",
    "            while j<(len(i)):\n",
    "                if i[j]=='@':\n",
    "                    if b=='':\n",
    "                        b+=i[0:j]\n",
    "                    b=b.replace('.','')\n",
    "                    b+=i[j:]\n",
    "                    break\n",
    "                elif i[j]=='+':\n",
    "                    b+=i[0:j]\n",
    "                    j=i.index('@')\n",
    "                else:\n",
    "                    j+=1\n",
    "            if b not in a:\n",
    "                a.append(b)\n",
    "        return len(a)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        result = set()\n",
    "        for email in emails:\n",
    "            address = []\n",
    "            flag1 = True\n",
    "            flag2 = False\n",
    "            for str in email:\n",
    "                if str=='.' and not flag2:\n",
    "                    continue\n",
    "                if str=='+' and not flag2:\n",
    "                    flag1 = False\n",
    "                if str==\"@\":\n",
    "                    flag1 = True\n",
    "                    flag2 = True\n",
    "                if flag1:\n",
    "                    address.append(str)\n",
    "            result.add(\"\".join(address))\n",
    "        return len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        store = set()\n",
    "        for email in emails:\n",
    "            local, domain = email.split('@')\n",
    "            local = local.split('+')[0]\n",
    "            local = local.replace('.', '')\n",
    "            store.add(local + '@' + domain)     \n",
    "        return len(store)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emails = [email.split('@') for email in emails]\n",
    "        for email in emails:\n",
    "            s = ''\n",
    "            for c in email[0]:\n",
    "                if c == '+':\n",
    "                    break\n",
    "                if c!='.':\n",
    "                    s += c\n",
    "            email[0] = s\n",
    "        emails = set(['@'.join(email) for email in emails])\n",
    "        return len(emails) \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        se = set()\n",
    "        for email in emails:\n",
    "            name, domain = email.split('@')\n",
    "            se.add(name.split('+')[0].replace('.', '') + '@' + domain)\n",
    "        # print(se)\n",
    "        return len(se)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "\n",
    "        emailSet = set()  # 字符串集合\n",
    "\n",
    "        for email in emails:\n",
    "            # 找到“@”符号\n",
    "            i = email.index('@')\n",
    "\n",
    "            local = email[:i].split('+', 1)[0]\n",
    "\n",
    "            local = local.replace('.','')\n",
    "\n",
    "            emailSet.add(local + email[i:])\n",
    "\n",
    "        return len(emailSet)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len(set(sp[0].split('+')[0].replace('.', '')+'@'+sp[1] if (sp := email.split('@')) else '' for email in emails))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+', 1)[0]\n",
    "            local = local.replace('.', '')\n",
    "            emailSet.add(local + email[i:])\n",
    "        return len(emailSet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        dic = dict()\n",
    "        res = 0\n",
    "        for i in emails:\n",
    "            new_email = i.split('@')\n",
    "            local = new_email[0].replace('.', '')\n",
    "            if '+' in local:\n",
    "                inde = local.index(\"+\")\n",
    "                local = local[:inde]\n",
    "            domain = new_email[1]\n",
    "            if local not in dic:\n",
    "                dic[local] = []\n",
    "                dic[local].append(domain)\n",
    "            else:\n",
    "                dic[local].append(domain)\n",
    "        print(dic)\n",
    "        for k, v in dic.items():\n",
    "            dic[k] = list(set(v))\n",
    "            res += len(dic[k])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len(set([i.split('@')[0].split('+')[0].replace('.','')+'@'+i.split('@')[1] for i in emails]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "      # loop arr, split(\"@\")\n",
    "      # local name \n",
    "        # cut + to @\n",
    "        # replace \".\" to \"\"\n",
    "      \n",
    "      cache = set()\n",
    "\n",
    "      for email in emails:\n",
    "         [name, domain] = email.split(\"@\") \n",
    "         name = name.split(\"+\")[0]\n",
    "         name = name.replace(\".\", \"\")\n",
    "\n",
    "         cache.add(\"@\".join([name, domain]))\n",
    "      \n",
    "\n",
    "      return len(cache)\n",
    "\n",
    "      \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def process(email):\n",
    "    local, domain = email.split('@')\n",
    "    i = local.find('+')\n",
    "    if i >= 0:\n",
    "        local = local[:i]\n",
    "    return local.translate(str.maketrans({'.': None})) + '@' + domain\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len({process(email) for email in emails})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res = set()\n",
    "        for address in emails:\n",
    "            a,b = address.split(\"@\")\n",
    "            a = a.split(\"+\")[0].replace(\".\",\"\")\n",
    "            address = a + \"@\" + b\n",
    "            res.add(address)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans = {}\n",
    "        n = len(emails)\n",
    "        for i in range(n):\n",
    "            #temp = emails[i]\n",
    "            #temp = temp.split(\"@\")\n",
    "            #email = temp[0].replace(\".\", \"\")\n",
    "            #ans[email.split(\"+\")[0] + \"@\" + temp[1]] = 0\n",
    "            ans[ emails[i].split(\"@\")[0].replace(\".\", \"\").split(\"+\")[0] + \"@\" + emails[i].split(\"@\")[1]  ] = 0\n",
    "        print(ans)\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+', 1)[0]\n",
    "            local = local.replace('.', '')\n",
    "            emailSet.add(local+email[i:])\n",
    "        return len(emailSet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        s=set()\n",
    "        tmp=[]\n",
    "        for email in emails:\n",
    "            tmp=[]\n",
    "            flagat=0\n",
    "            flagplus=0\n",
    "            for ch in email:\n",
    "                if ch=='@':\n",
    "                    flagat=1\n",
    "                    tmp.append(ch)\n",
    "                if ch=='+':\n",
    "                    flagplus=1\n",
    "                if ch.isalpha():\n",
    "                    if flagat==1 or flagplus==0:\n",
    "                        tmp.append(ch)\n",
    "                if ch=='.' and flagat==1:\n",
    "                    tmp.append(ch)\n",
    "            s.add(''.join(tmp))\n",
    "        return len(s)\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\r\n",
    "        ans = list()\r\n",
    "        def method(a):\r\n",
    "            a = a.split('@')\r\n",
    "            if '+' in a[0]:\r\n",
    "                a[0] = a[0].split('+')[0]\r\n",
    "            if '.' in a[0]:\r\n",
    "                a[0] = a[0].replace('.','')\r\n",
    "            return(a)\r\n",
    "        for i in emails:\r\n",
    "            if method(i) not in ans:\r\n",
    "                ans.append(method(i))\r\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+', 1)[0]  # 去掉本地名第一个加号之后的部分\n",
    "            local = local.replace('.', '')  # 去掉本地名中所有的句点\n",
    "            emailSet.add(local + email[i:])\n",
    "        return len(emailSet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        unique_emails = set()\n",
    "        for email in emails:\n",
    "            local,domain = email.split('@')\n",
    "            local = local.split('+')[0].replace('.','')\n",
    "            normalized_email = local + '@' + domain\n",
    "            unique_emails.add(normalized_email)\n",
    "        return len(unique_emails)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        return len(set(sp[0].split(\"+\")[0].replace(\".\", \"\") + \"@\" + sp[1] if (sp := email.split(\"@\")) else \"\" for email in emails))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res=set()\n",
    "        for ele in emails:\n",
    "            data=ele.split(\"@\")\n",
    "            local=data[0].split(\"+\")[0].replace(\".\",\"\")\n",
    "            host=data[1]\n",
    "            val=local+\"@\"+host\n",
    "            res.add(val)\n",
    "        return len(res)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans=set()\n",
    "        for email in emails:\n",
    "            i=email.index('@')\n",
    "            b=email[:i].split('+',1)[0]\n",
    "            b=b.replace('.','')\n",
    "            ans.add(b+email[i:])\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def checkemail(self, email):\n",
    "        email = email.split('@')\n",
    "        local = email[0].split('+')\n",
    "        email[0] = re.sub(r'[.]', '', local[0])\n",
    "        return '@'.join(email)\n",
    "\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        for idx, email in enumerate(emails):\n",
    "            emails[idx] = self.checkemail(email)\n",
    "        print(emails)\n",
    "        return len(set(emails))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        fullname = []\n",
    "        for string in emails:\n",
    "            names = string.split('@')\n",
    "            name = \"\"\n",
    "            for letter in names[0]:\n",
    "                if letter != '.' and letter != '+':\n",
    "                    name += letter\n",
    "                elif letter == '.':\n",
    "                    continue\n",
    "                elif letter == '+':\n",
    "                    break\n",
    "            fullname.append(name+'@'+names[1])\n",
    "        print(fullname)\n",
    "        fullname = list(set(fullname))\n",
    "        return len(fullname)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res = []\n",
    "        for em in emails:\n",
    "            name,loc = em.split('@')\n",
    "            name = name.split('+')[0].replace('.','')\n",
    "            em = name+'@'+loc\n",
    "            if em not in res:\n",
    "                res.append(em)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "         ans = set()\n",
    "         for ele in emails:\n",
    "             k = ele.index('@')\n",
    "             if ele[:k].count('+'):\n",
    "                 j = ele.index('+')\n",
    "                 head = ele[:j].replace('.', '')  # +前面部分\n",
    "             else:  # 没有+号，就以@做分隔\n",
    "                 head = ele[:k].replace('.', '')\n",
    "             ans.add(head + ele[k:])\n",
    "         return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        size = len(emails)\n",
    "        el = []\n",
    "        tl = []\n",
    "        for i in range(size):\n",
    "            tl.clear()\n",
    "            obj = re.match(\"(.+)@(.+.com)\", emails[i])\n",
    "            if obj:\n",
    "                s = obj.group(1).replace('.', '')\n",
    "                o1 = re.match(\"(.+?)\\+(.*)\", s)\n",
    "                if o1:\n",
    "                    s = o1.group(1)\n",
    "                # tl.extend([s, obj.group(2)])\n",
    "                tl.append(s)\n",
    "                tl.append(obj.group(2))\n",
    "                if tl not in el:\n",
    "                    el.append(tl[:])\n",
    "        return len(el)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        emailSet = set()\n",
    "        for email in emails:\n",
    "            i = email.index('@')\n",
    "            local = email[:i].split('+',1)[0]\n",
    "            local = local.replace('.','')\n",
    "            emailSet.add(local+email[i:])\n",
    "        \n",
    "        return len(emailSet)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        result = set()\n",
    "        for email in emails:\n",
    "            address = []\n",
    "            flag1 = True\n",
    "            flag2 = False\n",
    "            for str in email:\n",
    "                if str=='.' and not flag2:\n",
    "                    continue\n",
    "                if str=='+' and not flag2:\n",
    "                    flag1 = False\n",
    "                if str==\"@\":\n",
    "                    flag1 = True\n",
    "                    flag2 = True\n",
    "                if flag1:\n",
    "                    address.append(str)\n",
    "            result.add(\"\".join(address))\n",
    "        return len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        res = []\n",
    "        for i in emails:\n",
    "            right = ''\n",
    "            for j in range(len(i)):\n",
    "                target = i.index('@')\n",
    "                if i[j]=='.' and j< target:\n",
    "                    continue\n",
    "                elif i[j]=='+':\n",
    "                    right += i[target:]\n",
    "                    break\n",
    "                else:\n",
    "                    right += i[j]\n",
    "            res.append(right)\n",
    "        return len(set(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        ans = []\n",
    "        for ele in emails:\n",
    "            k = ele.index('@')\n",
    "            tail = ele[k:]  # @及@后面部分\n",
    "            if ele[:k].count('+'):\n",
    "                j = ele.index('+')\n",
    "                head = ele[:j].replace('.', '')  # +前面部分\n",
    "            else:\n",
    "                head = ele[:k].replace('.', '')\n",
    "            ans.append(head + tail)\n",
    "        return len(set(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numUniqueEmails(self, emails: List[str]) -> int:\n",
    "        dic = dict()\n",
    "        res = 0\n",
    "        for i in emails:\n",
    "            new_email = i.split('@')\n",
    "            local = new_email[0].replace('.', '')\n",
    "            if '+' in local:\n",
    "                inde = local.index(\"+\")\n",
    "                local = local[:inde]\n",
    "            domain = new_email[1]\n",
    "            if local not in dic:\n",
    "                dic[local] = []\n",
    "                dic[local].append(domain)\n",
    "            else:\n",
    "                dic[local].append(domain)\n",
    "\n",
    "        for k, v in dic.items():\n",
    "            dic[k] = list(set(v))\n",
    "            res += len(dic[k])\n",
    "        return res"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
